<?php

$cache_time=10;
$OJ_CACHE_SHARE=false;
$view_title= "开心一下,皮一下";
require_once("config/path_config.php");
require_once('./include/cache_start.php');
require_once('./include/db_info.inc.php');
require_once('./include/setlang.php');
require_once('./common/result_id.php');
require_once("./include/const.inc.php");
require_once("./config/privliege_config.php");
require_once (ROOTDIR."config/sys_config.php");
require_once (ROOTDIR."front/model/down_log_model.php");
@session_start();

// 判断输入参数是否正确
if ( !isset($_GET['sid']) || !isset($_SESSION['user_id']) ){
	echo "未查询到相关信息!\n";
	require_once("oj-footer.php");
	exit(0);
}

// 查询指定ID的提交信息,仅可以看自己提交的记录
$id = intval($_GET['sid']);
$sql="SELECT * FROM `solution` WHERE `solution_id`=?";
$result=pdo_query($sql, $id);
$row = null;
if ( $result ) {
    $row=$result[0];
}
if ( ! isset($row) || !isset($row['result']) ) {
    echo "未查询到相关信息!\n";
    require_once("oj-footer.php");
    exit(0);
}

// 题目ID
$problem_id = $row['problem_id'];
if ( intval($row['result']) != ResultID::ID_AC ) {
    echo "不好意思，本次提交不正确! 加油！<br/>";
    if ( $row['user_id'] == $_SESSION['user_id'] ) {
        echo "<a href='/problem.php?id=".$problem_id."'>点此继续努力(".$problem_id.")</a>";
    }
    require_once("oj-footer.php");
    exit(0);
}

$tipTxts = array(
    "我认为世界上最聪明的是牛顿，接着就是你!",
    "山崩地裂，水倒流，你是智慧与侠义的化身，帅气与美貌的结合!",
    '你的聪明才智，人见人爱，花见花开，车见车爆胎!',
    '性通畅以聪惠，行孊密而妍详。(释义：性情通达舒畅且聪慧，举止美丽缜密、巧妙审慎)',
    '伯仲之间见伊吕，指挥若定失萧曹。(释义：才华超绝与伊尹吕尚难分高下，指挥千军万马非曹参萧何能比)',
    '顶戴尊天地，聪明识见高。',
    '冰雪净聪明，雷霆走精锐。',
    '仰天大笑出门去，我辈岂是蓬蒿人！',
    '天生我材必有用，千金散尽还复来！',
    '我本楚狂人，凤歌笑孔丘！',
    '你是电，你是光，你就是那传说已久的神话!');
$tipCnt = count($tipTxts);
$tip_txt = $tipTxts[ $id % $tipCnt];

$handle = opendir(ROOTDIR.'upload/happy');
$fileUrls = array();
if ( $handle )
{
    while (($file = readdir($handle)) !== false) {
        //去除特殊目录
        if ( $file == "." || $file == "..") {
            continue;
        }
        //获取目录数组
        $url = "/upload/happy/".$file;
        array_push($fileUrls, $url);
    }
    closedir($handle);
}
$total_score = 100;
$img_url = "";
$cnt = count($fileUrls);
if ( $cnt > 0 ) {
    $idx = $id % $cnt;
    $img_url = $fileUrls[$idx];
}

/////////////////////////Template
require("template/bs3/happy_tpl.php");
/////////////////////////Common foot
if(file_exists('./include/cache_end.php'))
	require_once('./include/cache_end.php');
?>

